package com.hava.homework;

import com.hava.homework.service.PrintService;
import com.hava.homework.service.ThrowService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;

/**
 * Created by yanfa on 2016/10/16.
 */
public class MainAOP {

    public static void main(String [] args){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("homework-context.xml");
        PrintService printService = applicationContext.getBean("printService",PrintService.class);
        ThrowService throwService = applicationContext.getBean("throwService",ThrowService.class);

        try {
            System.out.println("[printService.create]:" + printService.create("test",123,new ArrayList<String>()));
            System.out.println("[printService.update]:" + printService.update());
            System.out.println("[printService.retrieve]:" + printService.retrieve());
            System.out.println("[printService.delete]:" + printService.delete());
        }
        catch (Exception e) {
        }


        try {
            System.out.println("[throwService.create]:" + throwService.create());
        } catch (Exception e) {
            System.out.println("Main catch throwService.create exception:" + e.toString());
        }
        try {
            System.out.println("[throwService.update]:" + throwService.update());
        } catch (Exception e) {
            System.out.println("Main catch throwService.update exception:" + e.toString());
        }
        try {
            System.out.println("[throwService.retrieve]:" + throwService.retrieve());
        } catch (Exception e) {
            System.out.println("Main catch throwService.retrieve exception:" + e.toString());
        }
        try {
            System.out.println("[throwService.delete]:" + throwService.delete());
        } catch (Exception e) {
            System.out.println("Main catch throwService.delete exception:" + e.toString());
        }

        ((ConfigurableApplicationContext) applicationContext).close();
    }
}
